package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.activity.client.ActivityFeignClient;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ActivityController {

    @Autowired
    private ActivityFeignClient activityFeignClient;


    /**
     * 秒杀列表
     *
     * @param model
     * @return
     */
    @GetMapping("seckill.html")
    public String index(Model model) {
        Result result = activityFeignClient.findAll();
        model.addAttribute("list", result.getData());
        return "seckill/index";
    }

    @GetMapping("/seckill/{skuId}.html")
    public String seckillItem(@PathVariable Long skuId, Model model) {
        Result result = activityFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item", result.getData());

        return "seckill/item";
    }

    @GetMapping("seckill/queue.html")
    public String queue(HttpServletRequest request) {
        request.setAttribute("skuId",request.getParameter("skuId"));
        request.setAttribute("skuIdStr",request.getParameter("skuIdStr"));
        return "seckill/queue";
    }
}
